package com.itheima.Homework;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/*
*
* - 有stus.txt文件，文件内容如下
  ```java
  张三,23
  李四,24
  王五,25
  ```
- 读取”xxx.txt”文件，将每行数据封装为一个Student对象，并将Student对象存储到一个集合

- 遍历并打印集合的所有Student信息*/
public class Two {
    public static void main(String[] args) throws IOException {


        FileReader fi = new FileReader("day12\\stus.txt");
        BufferedReader b = new BufferedReader(fi);

        ArrayList<String> arrayList = new ArrayList<>();
        List<Student> list = new ArrayList<>();

        String s;
        while ((s = b.readLine()) != null) {
            arrayList.add(s);
        }

        for (int i = 0; i < arrayList.size(); i++) {
            String s1 = arrayList.get(i);
            String[] split = s1.split(",");
            Student student = new Student(split[0],Integer.parseInt(split[1]));
            list.add(student);
        }

        System.out.println(list);

    }
}
